//===================================================获取用户ID=========================================================
var id=$.cookie("MYID");
if(id){

}else{
    location.href="index.html";
}
//    监听输入框状态
$(function(){
    $("#searchip").bind('input propertychange', function() {
        $(".myinfor").css("display","block");
        $("#newsplace").css("display","block");
        $("#searchlidt").css("display","none");
    });
});
//===================================================获取用户ID=========================================================
var id=$.cookie("MYID");
if(id){

}else{
    location.href="index.html";
}
//===================================================昵称搜索好友=======================================================
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13){ // enter 键
        $("#searchlidt div.ts_cells").remove();
        if($("#searchip").val()&&!$("#searchip").val().match(/\s/)){ //.match(/^\s+$/g)
            console.log($("#searchip").val());
            $.ajax({
                datatype:"json",
                type:"get",
                url:searchfriendurl+"?userId="+id+"&nick="+$("#searchip").val(),
                success:function(data){
                    console.log(data);
                    $(".myinfor").css("display","none");
                    $("#newsplace").css("display","none");
                    $("#searchlidt").css("display","block");
                    $("#searchtitlenum").html(data.Data.length);
                    if(data.Data&&data.Data.length>0){
                        for(var i=0;i<data.Data.length;i++){
                            var job="";
                            data.Data[i].index=i;
                            var reg=/([A-Za-z0-9\u4E00-\u9FA5])*/;
                            if(data.Data[i].jobs&&data.Data[i].jobs.length>0){
                                jobname=data.Data[i].jobs[0].typename;
                            }else if(data.Data[i].hobbys&&data.Data[i].hobbys.length>0){
                                jobname=data.Data[i].hobbys[0].typename;
                            }else{
                                jobname="";
                            }
                            $("#searchlidt").append("<div class='ts_cells'><a href='otherpeoplepage.html?otherid="+data.Data[i].userId+"'><div class='Cell'> <div class='tc_image userimgbox'><img src='"+imgurl+data.Data[i].headimg+"' class='topic_photo_img'/></div><div class='newsplaceright'><div class='title'>"+data.Data[i].nick+" </div><div class='words'>"+job+"</div></div></div></a></div>");
                        }
                        //调整图片区域大小
                        $(".userimgbox").height($(".userimgbox").eq(0).width());
                        var wid=document.getElementsByClassName("userimgbox")[0].style.width;
                        console.log(wid);
                    };
                }
            });
        }
    }
};
$("#serachbtn").click(function(){
    $("#searchlidt div.ts_cells").remove();
    if($("#searchip").val()&&!$("#searchip").val().match(/\s/)){ //.match(/^\s+$/g)
        console.log($("#searchip").val());
        $.ajax({
            datatype:"json",
            type:"get",
            url:searchfriendurl+"?userId="+id+"&nick="+$("#searchip").val(),
            success:function(data){
                console.log(data);
                $(".myinfor").css("display","none");
                $("#newsplace").css("display","none");
                $("#searchlidt").css("display","block");
                $("#searchtitlenum").html(data.Data.length);
                if(data.Data&&data.Data.length>0){
                    for(var i=0;i<data.Data.length;i++){
                        var job="";
                        data.Data[i].index=i;
                        var reg=/([A-Za-z0-9\u4E00-\u9FA5])*/;
                        if(data.Data[i].jobs&&data.Data[i].jobs.length>0){
                            jobname=data.Data[i].jobs[0].typename;
                        }else if(data.Data[i].hobbys&&data.Data[i].hobbys.length>0){
                            jobname=data.Data[i].hobbys[0].typename;
                        }else{
                            jobname="";
                        }
                        $("#searchlidt").append("<div class='ts_cells'><a href='otherpeoplepage.html?otherid="+data.Data[i].userId+"'><div class='Cell'> <div class='tc_image userimgbox'><img src='"+imgurl+data.Data[i].headimg+"' class='topic_photo_img'/></div><div class='newsplaceright'><div class='title'>"+data.Data[i].nick+" </div><div class='words'>"+job+"</div></div></div></a></div>");
                    }
                    //调整图片区域大小
                    $(".userimgbox").height($(".userimgbox").eq(0).width());
                    var wid=document.getElementsByClassName("userimgbox")[0].style.width;
                    console.log(wid);
                };
            }
        });
    }
});
//    监听输入框状态
$(function(){
    $("#searchip").bind('input propertychange', function() {
        $(".myinfor").css("display","block");
        $("#newsplace").css("display","block");
        $("#searchlidt").css("display","none");
    });
});